//package com.nari.ysphd.com.aspsine.swipetoloadlayout.view;
//
//import okhttp3.Call;
//
//import android.annotation.SuppressLint;
//import android.app.Activity;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.drawable.ColorDrawable;
//import android.com.aspsine.swipetoloadlayout.view.LayoutInflater;
//import android.com.aspsine.swipetoloadlayout.view.MotionEvent;
//import android.com.aspsine.swipetoloadlayout.view.View;
//import android.com.aspsine.swipetoloadlayout.view.View.OnClickListener;
//import android.com.aspsine.swipetoloadlayout.view.View.OnTouchListener;
//import android.com.aspsine.swipetoloadlayout.view.ViewGroup;
//import android.com.aspsine.swipetoloadlayout.view.ViewGroup.LayoutParams;
//import android.com.aspsine.swipetoloadlayout.view.WindowManager;
//import android.widget.BaseAdapter;
//import android.widget.Button;
//import android.widget.ListView;
//import android.widget.PopupWindow;
//import android.widget.TextView;
//
//import com.jeremyfeinstein.okhttputil.callback.StringCallback;
//import com.jeremyfeinstein.utils.YCHSWebSocketAPI;
//import com.nari.ysphd.R;
//import com.jeremyfeinstein.gson.OnResponse;
//import com.jeremyfeinstein.gson.SendMessage;
//import com.nari.ysphd.ui.ConferenceRoomUI;
//import com.jeremyfeinstein.utils.AppConstants;
//import com.jeremyfeinstein.utils.ConfigUtil;
//import com.jeremyfeinstein.utils.YCHSInstance;
//import com.jeremyfeinstein.utils.YCHShttpAPI;
//
///*8
// * 消息弹框
// */
//public class MessageDialog extends PopupWindow {
//
//	private View mMenuView;
//	public Activity window;
//	public ListView ll_item;
//	private Button btn_cancel;
//	private MessageAdapter mAdapter;
//
//	@SuppressWarnings("deprecation")
//	public MessageDialog(final Activity context) {
//		super(context);
//
//		LayoutInflater inflater = (LayoutInflater) context
//				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		mMenuView = inflater.inflate(R.layout.view_messagedialog, null);
//		ll_item = (ListView) mMenuView.findViewById(R.id.ll_item);
//		btn_cancel = (Button) mMenuView.findViewById(R.id.btn_cancel);
//		window = context;
//		mAdapter = new MessageAdapter(context);
//		ll_item.setAdapter(mAdapter);
//		// 设置按钮监听
//		// 设置SelectPicPopupWindow的View
//		this.setContentView(mMenuView);
//		// 设置SelectPicPopupWindow弹出窗体的宽
//		this.setWidth(LayoutParams.WRAP_CONTENT);
//		// 设置SelectPicPopupWindow弹出窗体的高
//		this.setHeight(LayoutParams.WRAP_CONTENT);
//		// 设置SelectPicPopupWindow弹出窗体可点�?
//		this.setFocusable(true);
//		// 设置SelectPicPopupWindow弹出窗体动画效果
//		this.setAnimationStyle(R.style.PopupAnimation);
//		// 实例化一个ColorDrawable颜色为半透明
//		ColorDrawable dw = new ColorDrawable(window.getResources().getColor(
//				R.color.transparent));
//		// 设置SelectPicPopupWindow弹出窗体的背景
//		this.setBackgroundDrawable(dw);
//		// 添加pop窗口关闭事件
//		this.setOnDismissListener(new poponDismissListener());
//		// mMenuView添加OnTouchListener监听判断获取触屏位置如果在�?�择框外面则�?毁弹出框
//		mMenuView.setOnTouchListener(new OnTouchListener() {
//			@SuppressLint("ClickableViewAccessibility")
//			public boolean onTouch(View v, MotionEvent event) {
//
//				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
//				int heightmin = mMenuView.findViewById(R.id.pop_layout)
//						.getBottom();
//				int y = (int) event.getY();
//				if (event.getAction() == MotionEvent.ACTION_UP) {
//					if (y < height) {
//						dismiss();
//					}
//					if (y > heightmin) {
//						dismiss();
//					}
//				}
//				return true;
//			}
//		});
//		btn_cancel.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				dismiss();
//			}
//		});
//	}
//
//	/**
//	 * 弹出的popWin关闭的事件，主要是为了将背景透明度改回来
//	 *
//	 * @author cg
//	 *
//	 */
//	class poponDismissListener implements PopupWindow.OnDismissListener {
//
//		@Override
//		public void onDismiss() {
//			WindowManager.LayoutParams params = window.getWindow()
//					.getAttributes();
//			params.alpha = 1f;
//			window.getWindow().setAttributes(params);
//		}
//
//	}
//}
//
//class MessageAdapter extends BaseAdapter {
//
//	private Context context;
//
//	public MessageAdapter(Context context) {
//		this.context = context;
//	}
//
//	@Override
//	public int getCount() {
//		return YCHSInstance.getApp().getSendMessages().size();
//	}
//
//	@Override
//	public Object getItem(int position) {
//		return YCHSInstance.getApp().getSendMessages().get(position);
//	}
//
//	@Override
//	public long getItemId(int position) {
//		return 0;
//	}
//
//	@Override
//	public View getView(final int position, View convertView, ViewGroup parent) {
//		convertView = LayoutInflater.from(context).inflate(R.layout.item_meetlist_invite, null);
//		TextView room_name = (TextView)convertView.findViewById(R.id.room_name);
//		TextView room_creater = (TextView)convertView.findViewById(R.id.room_creater);
//		TextView room_date = (TextView)convertView.findViewById(R.id.room_date);
//		final SendMessage msg = (SendMessage)getItem(position);
//		room_name.setText(msg.getCONTENT());
//		room_creater.setText("主持人:"+msg.getHOST_NAME());
//		room_date.setText(msg.getSTART_TIME()+"~"+msg.getEND_TIME());
//		Button btn_join = (Button) convertView
//				.findViewById(R.id.join_button);
//		btn_join.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//
//				String url = "";
//				if (AppConstants.isLocalMeeting){
//					url = ConfigUtil.getApp().getLocalSocketUrl();
//				}else {
//					url = ConfigUtil.getApp().getRemoteSocketUrl();
//				}
//				YCHShttpAPI.CheckJoinMeeting(context, url, msg.getMEETING_ID(), msg.getINVITE_CODE(),"0" , new StringCallback() {
//					@Override
//					public void onResponse(String response) {
//						System.out.println("CheckJoinMeeting:"+response);
//						OnResponse onResponse = YCHShttpAPI.getOnResponse(response);
//						ConfigUtil.getApp().setMCUPort(ConfigUtil.getApp().getLocalPort4());
//						ConfigUtil.getApp().setTurnPort(ConfigUtil.getApp().getLocalPort3());
//						AppConstants.turnAddrTCP = "turn:"+ConfigUtil.getApp().getRemoteUrl()+":"+ConfigUtil.getApp().getTurnPort()+"?transport=tcp";
//
//						AppConstants.SERVER_URL = "http://"+ConfigUtil.getApp().getRemoteUrl()+":"+ConfigUtil.getApp().getRemotePort();
//						//YCHSWebSocketAPI.getApp().initSocket(YCHShttpAPI.getCookiesString(), ConfigUtil.getApp().getRemoteUrl(), ConfigUtil.getApp().getRemotePort());
//						AppConstants.isLocalMeeting = true;
//
//						if("0".equals(onResponse.getResultCode())){
//							Intent intent = new Intent(context,
//									ConferenceRoomUI.class);
//							intent.putExtra(ConferenceRoomUI.MCU_ROOMID, onResponse.getMcu_room_id());
//							intent.putExtra(ConferenceRoomUI.MEETING_ID, msg.getMEETING_ID());
//							intent.putExtra(ConferenceRoomUI.MEETING_NAME, msg.getMEETING_NAME());
//							intent.putExtra(ConferenceRoomUI.MCU_ROLE, onResponse.getRole());
//							intent.putExtra("flag", "2");
//							context.startActivity(intent);
//
////							YCHSInstance.getApp().getSendMessages().remove(position);
//						}
//					}
//
//					@Override
//					public void onError(Call call, int statusCode, Exception e) {
//
//					}
//				});
//			}
//		});
//		return convertView;
//	}
//
//}